package com.yimils.core.goods.controller;

import com.yimils.core.common.dto.RspBase;
import com.yimils.core.goods.dto.BrandAddReq;
import com.yimils.core.goods.dto.BrandUpdateReq;
import com.yimils.core.goods.serivce.BrandService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Validated
public class BrandController {
    @Resource(name = "brandService")
    BrandService brandService;

    /**
     * showdoc
     *
     * @return {"code":0,"msg":"操作成功"}
     * @catalog 品牌管理/品牌管理
     * @title 添加品牌
     * @description 添加品牌
     * @json_param {"brandName":"特步","supplierId":"32"}
     * @method post
     * @url /brand/save
     * @return_param code   Integer     状态码
     * @return_param msg   String    消息
     * @number 3
     */
    @PostMapping("/brand/save")
    public RspBase saveBrand(@RequestBody BrandAddReq brandAddReq) {
        if (brandService.saveBrand(brandAddReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    /**
     * showdoc
     *
     * @return {"code":0,"msg":"操作成功"}
     * @catalog 品牌管理/品牌管理
     * @title 修改品牌
     * @description 修改品牌
     * @json_param {"brandId":"2","brandName":"美邦123123"}
     * @method put
     * @url /brand/update
     * @return_param code   Integer     状态码
     * @return_param msg   String    消息
     * @number 3
     */
    @PutMapping("/brand/update")
    public RspBase updateBrand(@RequestBody BrandUpdateReq brandUpdateReq) {
        if (brandService.updateBrand(brandUpdateReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    /**
     * showdoc
     *
     * @return {"code":0,"msg":"操作成功"}
     * @catalog 品牌管理/品牌管理
     * @title 删除品牌
     * @description 删除品牌
     * @json_param [2,3]
     * @method delete
     * @url /brand/delete
     * @return_param code   Integer     状态码
     * @return_param msg   String    消息
     * @number 3
     */
    @DeleteMapping("/brand/delete")
    public RspBase deleteBrand(@RequestBody List<Long> brandIds) {
        if (brandService.deleteBrand(brandIds)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    /**
     * showdoc
     *
     * @return  {"code":200,"msg":"","data":[{"brandId":3,"brandName":"特步"}]}
     * @catalog 品牌管理/品牌管理
     * @title 品牌列表
     * @description 品牌列表
     * @json_param [2]
     * @method get
     * @url /brand/list
     * @return_param code   Integer     状态码
     * @return_param msg   String    消息
     * @return_param brandId   Long    品牌id
     * @return_param brandName   String    品牌名称
     * @number 3
     */
    @GetMapping("/brand/list")
    public RspBase listBrand(Long supplierId) {
        RspBase rsp = RspBase.OK();
        rsp.put("data", brandService.listBrand(supplierId));
        return rsp;
    }

}
